<template>
  <div class="gantt-page">
    <div class="gantt-header">
      <div class="header-left">
        <el-icon class="back-icon" @click="$router.back()">
          <ArrowLeft />
        </el-icon>
        <h2>{{ projectName }} - 甘特图</h2>
      </div>
      <div class="header-actions">
        <el-button-group>
          <el-button :type="viewMode === 'day' ? 'primary' : ''" @click="viewMode = 'day'" size="small">日</el-button>
          <el-button :type="viewMode === 'week' ? 'primary' : ''" @click="viewMode = 'week'" size="small">周</el-button>
          <el-button :type="viewMode === 'month' ? 'primary' : ''" @click="viewMode = 'month'" size="small">月</el-button>
        </el-button-group>
      </div>
    </div>

    <div class="gantt-body">
      <div class="gantt-placeholder">
        <el-icon :size="100" color="#409eff"><TrendCharts /></el-icon>
        <h3>甘特图视图</h3>
        <p>展示项目时间线和任务依赖关系</p>
        <el-alert
          title="提示：甘特图功能需要集成专业图表库（如：dhtmlx-gantt、frappe-gantt）"
          type="info"
          :closable="false"
          style="margin-top: 20px; max-width: 600px"
        />
        <div class="gantt-preview">
          <div class="timeline-row" v-for="task in tasks" :key="task.id">
            <div class="task-name">{{ task.name }}</div>
            <div class="timeline">
              <div 
                class="task-bar" 
                :style="{ 
                  width: task.duration + '%', 
                  marginLeft: task.offset + '%',
                  background: task.color
                }"
              >
                <span>{{ task.duration }}%</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ArrowLeft, TrendCharts } from '@element-plus/icons-vue'

const projectName = ref('ERP系统开发')
const viewMode = ref('month')

const tasks = ref([
  { id: 1, name: '需求分析', duration: 20, offset: 0, color: '#409eff' },
  { id: 2, name: 'UI设计', duration: 15, offset: 20, color: '#67c23a' },
  { id: 3, name: '前端开发', duration: 30, offset: 35, color: '#e6a23c' },
  { id: 4, name: '后端开发', duration: 30, offset: 35, color: '#f56c6c' },
  { id: 5, name: '测试', duration: 15, offset: 65, color: '#909399' },
  { id: 6, name: '上线', duration: 5, offset: 80, color: '#67c23a' }
])
</script>

<style scoped>
.gantt-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
}

.gantt-header {
  height: 60px;
  background: white;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.back-icon {
  font-size: 20px;
  cursor: pointer;
}

.header-left h2 {
  margin: 0;
  font-size: 18px;
}

.gantt-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.gantt-placeholder {
  text-align: center;
}

.gantt-placeholder h3 {
  margin: 20px 0 10px;
  color: #303133;
}

.gantt-placeholder p {
  color: #606266;
  margin-bottom: 20px;
}

.gantt-preview {
  margin-top: 30px;
  max-width: 800px;
}

.timeline-row {
  display: flex;
  gap: 20px;
  margin-bottom: 15px;
}

.task-name {
  width: 150px;
  text-align: right;
  font-size: 14px;
  padding-top: 8px;
}

.timeline {
  flex: 1;
  height: 32px;
  background: #f0f0f0;
  border-radius: 4px;
  position: relative;
}

.task-bar {
  height: 100%;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: bold;
}
</style>

